<template>
	<div>
		<!-- <div class="topheader">
      <div class="roof"></div>
    </div> -->
		<!-- <div class="slot"></div> -->
		<div class="header" :class="{active:active}">
			<!-- <div>
				
				<slot></slot>
			</div> -->
			<div class="btn">
				<img @click="returnGo" src="@/assets/homeimg/back.png" />
			</div>
			<div class="title">{{title}}</div>
		</div>
	</div>
</template>
<script>
	export default {
		props:{
			courseType:{
				type:String,
				default: '0'
			}
		},
		data() {
			return {
				title:'',
				type: null,
				active:false,
			}
		},
		watch: {
			"$route.path": function(newVal, oldVal) {
			if (this.$route.query.title) {
				this.title = this.$route.query.title;
				return;
			}
			this.title = this.$route.meta.title;
			}
		},
		mounted() {
			//课程记录页面返回
			if(this.$route.query.course_type){
				this.courseType = this.$route.query.course_type
			}
			//判断地址页面返回
			if(this.$route.query.type){
				// console.log(this.$route.query.type)
				this.type = this.$route.query.type
			}
			if(this.$store.state.ios){
				this.active = true;
			}
			if (this.$route.query.title) {
				this.title = this.$route.query.title;
				return;
			}
			this.title = this.$route.meta.title;
			window.back = this.back;
		},
		methods:{
			returnGo() {
				// this.$router.go(-1);
				// console.log(this.title,this.courseType)
				if(this.title == '购买课程'){
					if(this.courseType == 1){
						this.$router.back();
						return
					}
				}
				if(this.title == '我的地址'){
					if(this.type == 1){
						this.$router.back();
						return
					}
				}
				if(
					this.title == '我的积分' || this.title == '我的地址' || this.title == "设置" || this.title == '购买课程' ||
					this.title == '邀请好友' || this.title == '个人信息' || this.title == '学习日历' || this.title == "系统消息" || 
					this.title == "课程详情" || this.title == '我的老师' || this.title == '学习报告' || this.title == "课程提醒" ||
					this.title == '添加二维码' || this.title == '隐私协议'
				){
					window.h5_android && window.h5_android.reback();
					window.webkit.messageHandlers.pageBack_js_oc.postMessage([]);
					return
				}
				this.$router.back()
				
				// if(this.type){
				// 	if(this.type == 1){
				// 		this.$router.back()
				// 	}else{
				// 		window.h5_android && window.h5_android.reback();
				// 		window.webkit.messageHandlers.pageBack_js_oc.postMessage([]);
				// 	}
				// }else{
				// 	if(
				// 		this.title == '我的积分' || this.title == '我的地址' || this.title == "设置" ||
				// 		this.title == '邀请好友' || this.title == '个人信息' || this.title == '学习日历' || this.title == "系统消息" || 
				// 		this.title == "课程详情" || this.title == '我的老师' || this.title == '学习报告'
				// 	){
				// 		window.h5_android && window.h5_android.reback();
				// 		window.webkit.messageHandlers.pageBack_js_oc.postMessage([]);
				// 		return
				// 	}
				// 	this.$router.back()
				// }
				
			},
		}
	}
</script>
<style lang="scss" scoped="scoped">
	.header {
		// font-weight: bold;
		width: 100vw;
		height: calc(11.7333vw + 0px);
		// box-sizing: border-box;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 10;
		border-bottom: 1px solid #dcdcdc;
		background: rgba(255, 255, 255, 1);
		// display: flex;
		// justify-content: center;
		.title {
			height: 11.7333vw;
			line-height: 11.7333vw;
			text-align: center;
			font-size: 5.3333vw;
			// margin-top: 24px;
		}
		.btn {
			position: absolute;
			top: 0px;
			left: 0;
			width: 11.4667vw;
			height: 11.7333vw;
			img {
				width: 3.4667vw;
				height: 5.3333vw;
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%);
			}
		}
		&.active{
			height: calc(11.7333vw + 24px);
			.title{
				margin-top: 24px;
			}
			.btn{
				top: 24px;
			}
		}
	}

	
</style>
